#!/usr/bin/env python

# --------------------------------------
# projects/python/primes/TestPrimes.py
# Copyright (C) 2009
# Glenn P. Downing
# --------------------------------------

# To run the tests
#     TestPrimes.py

# To document the tests
#     pydoc -w TestPrimes

import main
import unittest

# ----------
# TestReader
# ----------

class TestReader (object) :
    def __init__ (self, s) :
        self.s = s

    def read (self) :
        return self.s

# ----------
# TestWriter
# ----------

class TestWriter (object) :
    def str (self) :
        return self.s

    def write (self, *a) :
        self.s = str(a[0])
        for w in a[1:] :
            self.s += ' '
            self.s += str(w)
        self.s += '\n'

# -----------
# TestPrimes
# -----------

class TestPrimes (unittest.TestCase) :
    # ----
    # read
    # ----

	def test_read (self) :
		reader = TestReader('24\n')
		main.my_read(reader)
		self.assert_(main.x ==  24)

	# ----
	# eval
	# ----
	
	def test_eval1 (self) :
                main.x = -5
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 0)
                self.assert_(main.num2 == 0)
                self.assert_(main.num3 == 0)
                self.assert_(main.num4 == 0)

        def test_eval2 (self) :
                main.x = 0
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 0)
                self.assert_(main.num2 == 0)
                self.assert_(main.num3 == 0)
                self.assert_(main.num4 == 0)

        def test_eval3 (self) :
                main.x = 1
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 0)
                self.assert_(main.num2 == 0)
                self.assert_(main.num3 == 0)
                self.assert_(main.num4 == 0)

        def test_eval4 (self) :
                main.x = 2
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 0)
                self.assert_(main.num2 == 0)
                self.assert_(main.num3 == 0)
                self.assert_(main.num4 == 0)

        def test_eval5 (self) :
                main.x = 4
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 0)
                self.assert_(main.num2 == 0)
                self.assert_(main.num3 == 0)
                self.assert_(main.num4 == 0)

        def test_eval6 (self) :
                main.x = 8
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 2)
                self.assert_(main.num4 == 2)

        def test_eval7 (self) :
                main.x = 10
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 3)

        def test_eval8 (self) :
                main.x = 11
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 3)

        def test_eval9 (self) :
                main.x = 12
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 5)

        def test_eval10 (self) :
                main.x = 13
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 5)

        def test_eval11 (self) :
                main.x = 22
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 5)
                self.assert_(main.num4 == 13)

        def test_eval12 (self) :
                main.x = 29
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 5)
                self.assert_(main.num4 == 19)

        def test_eval13 (self) :
                main.x = 100
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 7)
                self.assert_(main.num4 == 89)

        def test_eval14 (self) :
                main.x = 1000
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 5)
                self.assert_(main.num4 == 991)

        def test_eval15 (self) :
                main.x = 10000
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 23)
                self.assert_(main.num4 == 9973)

        def test_eval16 (self) :
                main.x = 100000
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 5)
                self.assert_(main.num4 == 99991)

        def test_eval17 (self) :
                main.x = 1000000
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 13)
                self.assert_(main.num4 == 999983)

        def test_eval18 (self) :
                main.x = 10000000
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 5)
                self.assert_(main.num4 == 9999991)

        def test_eval19 (self) :
                main.x = 2345
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 7)
                self.assert_(main.num4 == 2333)

        def test_eval20 (self) :
                main.x = 876
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 13)
                self.assert_(main.num4 == 859)

        def test_eval21 (self) :
                main.x = 2345
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 7)
                self.assert_(main.num4 == 2333)

        def test_eval22 (self) :
                main.x = 9098
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 9091)

        def test_eval23 (self) :
                main.x = 345
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 337)
	
        def test_eval24 (self) :
                main.x = 1234
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 7)
                self.assert_(main.num4 == 1223)

        def test_eval25 (self) :
                main.x = 34
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 7)
                self.assert_(main.num4 == 23)

        def test_eval26 (self) :
                main.x = 67
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 59)

        def test_eval27 (self) :
                main.x = 37
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 29)

        def test_eval28 (self) :
                main.x = 6
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 0)
                self.assert_(main.num2 == 0)
                self.assert_(main.num3 == 0)
                self.assert_(main.num4 == 0)

        def test_eval29 (self) :
                main.x = 587678
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 5)
                self.assert_(main.num4 == 587669)

        def test_eval30 (self) :
                main.x = 234
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 227)

        def test_eval31 (self) :
                main.x = 45645
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 41)
                self.assert_(main.num4 == 45599)

        def test_eval32 (self) :
                main.x = 672342
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 67)
                self.assert_(main.num4 == 672271)

        def test_eval33 (self) :
                main.x = 5645
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 17)
                self.assert_(main.num4 == 5623)

        def test_eval34 (self) :
                main.x = 234234
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 13)
                self.assert_(main.num4 == 234217)

        def test_eval35 (self) :
                main.x = 567856
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 11)
                self.assert_(main.num4 == 567841)

        def test_eval36 (self) :
                main.x = 9754235
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 11)
                self.assert_(main.num4 == 9754219)

        def test_eval37 (self) :
                main.x = 9999999
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 9999991)

        def test_eval38 (self) :
                main.x = 6798
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 6791)

        def test_eval39 (self) :
                main.x = 53789
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 7)
                self.assert_(main.num4 == 53777)

        def test_eval40 (self) :
                main.x = 87654
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 2)
                self.assert_(main.num3 == 7)
                self.assert_(main.num4 == 87643)

        def test_eval41 (self) :
                main.x = 9999999
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 9999991)

        def test_eval42 (self) :
                main.x = 999999
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 11)
                self.assert_(main.num4 == 999983)

        def test_eval43 (self) :
                main.x = 99999
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 99991)

        def test_eval44 (self) :
                main.x = 9999
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 53)
                self.assert_(main.num4 == 9941)

        def test_eval45 (self) :
                main.x = 999
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 3)
                self.assert_(main.num4 == 991)

        def test_eval46 (self) :
                main.x = 99
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 5)
                self.assert_(main.num4 == 89)

        def test_eval47 (self) :
                main.x = 9
                main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
                self.assert_(main.num1 == 2)
                self.assert_(main.num2 == 3)
                self.assert_(main.num3 == 2)
                self.assert_(main.num4 == 2)
			
	
	# -----
	# print
	# -----

	def test_print (self) :
		main.x =  24
		main.num1 = 0
                main.num2 = 0
                main.num3 = 0
                main.num4 = 0
                main.my_eval()
		writer = TestWriter()
		main.my_print(writer)
		self.assert_(writer.str() == '2 2 3 17\n')

if __name__ == "__main__" :
    unittest.main()